package com.cloud.nacos.controller;

import com.cloud.nacos.client.TestClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

@RestController
@RefreshScope
public class TestController {


    @Value("${spring.application.name}")
    private String configValue;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @GetMapping("/getData")
    public Object getData() {
        return jdbcTemplate.queryForList("select * from config_info");
    }

    @GetMapping("/config")
    public Object getConfig() {
        return configValue;
    }


    @Autowired
    private TestClient testClient;

    @GetMapping("/get/{id}")
    public String getId(@PathVariable("id") Long id) {
        return testClient.getId(id);
    }

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/get2/{id}")
    public String getId2(@PathVariable("id") Long id) {
        return restTemplate.getForObject("http://feign-dev/feign-dev/get/" + id, String.class);
    }

}

